<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>管理员主页</title>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <link rel="stylesheet"  href="css/style1.css">
    <script type="text/javascript" src="http://libs.baidu.com/jquery/1.7.2/jquery.min.js"></script>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">

    <!-- layui的水平导航 -->
    <div class="layui-header">
        <div class="layui-logo"><strong>高校健康上报后台管理系统</strong></div>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <ul class="layui-nav layui-nav-tree"  lay-filter="test">
                <li class="layui-nav-item">
                    <a href="/admin1"><i class="layui-icon layui-icon-home"></i>  管理员主页</a>
                </li>
                <li class="layui-nav-item">
                    <a href="/userMange"><i class="layui-icon layui-icon-user"></i>  用户管理</a>
                </li>
                <li class="layui-nav-item layui-this">
                    <a href="/numberMange"><i class="layui-icon layui-icon-password"></i>  账号管理</a>
                </li>
                <li class="layui-nav-item">
                    <a href="/riskareaMange"><i class="layui-icon layui-icon-fire"></i>  风险地区管理</a>
                </li>
                <li class="layui-nav-item">
                    <a href="/adminMange"><i class="layui-icon layui-icon-user"></i>  管理员账号管理</a>
                </li>
                <li class="layui-nav-item">
                    <a href="/logout"><i class="layui-icon layui-icon-logout"></i>  退出系统</a>
                </li>
            </ul>
        </div>
    </div>

    <div class="layui-body">
        <div style="padding: 15px;">
            <div class="demoTable">
                查询条件:
                <div class="layui-inline">
                    <input class="layui-input" name="id" id="username" placeholder="请输入查询账号" autocomplete="off">
                </div>
                <div class="layui-inline">
                    <input class="layui-input" name="id" id="type" placeholder="请输入查询身份" autocomplete="off">
                </div>
                <div class="layui-inline">
                    <input class="layui-input" name="id" id="status" placeholder="请输入查询账号状态" autocomplete="off">
                </div>
                <button class="layui-btn" id="selectByCondition" data-type="reload">查询</button>
            </div>
            <table class="layui-hide" id="LAY_table_user" lay-filter="user"></table>
        </div>
    </div>
    <script src="../layui/layui.js"></script>

    <script type="text/html" id="btn">
        <a class="layui-btn layui-btn-sm layui-btn-normal" href="/lockaccount/{{d.uid}}">锁定账号</a>
        <a class="layui-btn layui-btn-sm layui-btn-warm" href="/unlockaccount/{{d.uid}}">解锁账号</a>
        <a class="layui-btn layui-btn-sm layui-btn-danger" lay-event="del">删除账号</a>
    </script>

    <script>
        layui.use('element', function(){
            var element = layui.element;

        });

        layui.use('table', function(){
            var table = layui.table;
            table.render({
                elem: '#LAY_table_user'
                ,url:'/usernumbermange'
                ,cellMinWidth: 80
                ,toolbar:true
                ,title:'用户数据表'
                ,totalRow:true
                ,cols: [
                    [
                        {field:'uid', title: 'ID', width:80, sort:true}
                        ,{field:'username', title: '用户', sort:true}
                        ,{field:'type', title: '身份', width:80}
                        ,{field:'status', title: '账号状态'}
                        ,{field: 'button', title: '操作', toolbar:"#btn"}
                    ]
                ]
                ,id: 'testReload'
            });
            var $ = layui.$, active = {
                reload: function(){
                    var username = $('#username');
                    var type = $('#type');
                    var status = $('#status');
                    console.log("key:" + username.val());
                    table.reload('testReload', {
                            url: '/selectUserNumberByCondition'
                            ,where: {
                                username:username.val(),
                                type:type.val(),
                                status:status.val(),
                            }
                        }
                    );
                }
            };
            $('.demoTable .layui-btn').on('click', function(){
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
            table.on('tool(user)', function(obj){
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
                if(layEvent === 'detail'){ //查看
                    //do somehing
                } else if(layEvent === 'del'){ //删除
                    layer.confirm('真的删除行么', function(index){
                        obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                        layer.close(index);
                        //向服务端发送删除指令
                        $.ajax({
                            url:'/deleteusernumber',
                            type:'get',
                            data:{'id':data.uid},//向服务端发送删除的id
                        });
                        layer.close(index);
                    });
                }
            });
        });
    </script>

</div>
</body>
</html>